package com.lcx.db137.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lcx.db137.common.R;
import com.lcx.db137.entity.Userrole;
import com.lcx.db137.service.impl.UserroleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
* (userrole)表控制层
*
* @author xxxxx
*/
@RestController
@CrossOrigin(origins = "*")
public class UserroleController {
/**
* 服务对象
*/
@Autowired
private UserroleServiceImpl userroleServiceImpl;
//根据用户id查询角色id
    @GetMapping("/selectroleIdByUserId")
    public R selectRoleIdByUserId(Integer userId) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userid", userId);
        List<Userrole> roles =  userroleServiceImpl.list(queryWrapper);
        return new R().add("roleId", roles);
    }
    //分配职位
    @PostMapping("/updateRoleIdByUserId")
    public R updateRoleIdByUserId(@RequestBody Map<String, Object> map) {
        Integer userId = (Integer) map.get("userId");
        List<Integer> roleId = (List<Integer>) map.get("roleId");
        boolean update = userroleServiceImpl.updateRoleIdByUserId(userId, roleId);
        return new R().add("b", update);
    }


}
